package com.wf.ew.relation.controller;

import com.wf.ew.common.BaseController;
import com.wf.ew.common.JsonResult;
import com.wf.ew.common.PageResult;
import com.wf.ew.relation.model.Custom;
import com.wf.ew.relation.service.CustomService;
import com.wf.ew.system.model.Company;
import com.wf.ew.system.model.Dictionarydata;
import com.wf.ew.system.service.DictionarydataService;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import net.sf.json.JSONArray;

/**
 *
 * controller
 * @author : Doman
 * @date : 2019-11-18 11:10:55
 * @version ：1.0
 */

@Controller
@RequestMapping("/relation/custom")
public class CustomController extends BaseController {

	@Autowired
	private CustomService customService;
	@Autowired
	private DictionarydataService dictionarydataService;
	
	/**
	 * 页面
	 **/

	@RequiresPermissions("custom:view")
	@RequestMapping()
	public String custom(Model model) {
		model.addAttribute("typeList",dictionarydataService.list(new Dictionarydata("custom_type")));
		return "relation/custom.html";
	}

	/**
	 * 选择页面
	 **/
	@RequestMapping(value = "/listSel")
	public String listSel(Model model, Custom custom) {
		model.addAttribute("custom",custom);
		return "relation/customSel.html";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("custom:view")
	@RequestMapping(value = "/list", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String list(PageResult<T> page, Custom custom){
		return customService.list(page, custom,getLoginUser());
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("custom:view")
	@RequestMapping(value = "/ajaxList", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String ajaxList(Custom custom){
		return JSONArray.fromObject(customService.list(custom,getLoginUser())).toString();
	}

	/**
	 * 新增
	 **/
	@RequiresPermissions("custom:add")
	@ResponseBody
	@RequestMapping("/add")
	public JsonResult add(Model model, Custom custom) {
		return customService.add(custom, getLoginUser());
	}

	/**
	 * 修改
	 **/
	@RequiresPermissions("custom:update")
	@ResponseBody
	@RequestMapping("/update")
	public JsonResult update(Model model, Custom custom) {
		return customService.update(custom, getLoginUser());
	}

	/**
	 * 批量删除
	 **/
	@RequiresPermissions("custom:delete")
	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(Custom custom ) {
		return customService.delete(custom, getLoginUser());
	}

}
